//
//  TabBarViewController.m
//  SmartCup
//
//  Created by Kendama on 2017/5/16.
//  Copyright © 2017年 DT. All rights reserved.
//

#import "TabBarViewController.h"

@interface TabBarViewController ()

@end

@implementation TabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setTabBarItem];

}


- (void)setTabBarItem
{
    
    NewsViewController *newsVC = [[NewsViewController alloc] init];
    newsVC.tabBarItem.title = @"消息";
    newsVC.navigationItem.title = @"消息";
    
    DeviceListViewController *deviceVC = [[DeviceListViewController alloc] init];
    deviceVC.tabBarItem.title = @"设备";
    deviceVC.navigationItem.title = @"设备";
    
    MeViewController *meVC = [[MeViewController alloc] init];
    meVC.tabBarItem.title = @"我的";
    meVC.navigationItem.title = @"我的";
    
    self.viewControllers = @[[self giveMeNavWithVC:newsVC andImgName:@"tab_news" andSelectedImgName:@"tab_news_pre"],
                             [self giveMeNavWithVC:deviceVC andImgName:@"tab_equipment" andSelectedImgName:@"tab_equipment_pre"],
                             [self giveMeNavWithVC:meVC andImgName:@"tab_my" andSelectedImgName:@"tab_my_pre"],
                            ];

    
}

/**
 *  快速创建Nav
 */
- (UINavigationController *)giveMeNavWithVC:(UIViewController *)VC andImgName:(NSString *)imgName andSelectedImgName:(NSString *)selImgName
{
    UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:VC];
//    nav.tabBarItem = [[UITabBarItem alloc] initWithTitle:VC.tabBarItem.title image:[self removeRendering:imgName] tag:0];
    nav.tabBarItem = [[UITabBarItem alloc] initWithTitle:VC.tabBarItem.title image:[self removeRendering:imgName] selectedImage:[self removeRendering:selImgName]];
    [nav.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#6F6F6F"]}
                                  forState:UIControlStateNormal];
    [nav.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#231916"]} forState:UIControlStateHighlighted];
//    [nav.tabBarItem setTitlePositionAdjustment:UIOffsetMake(0, -12)];
//    nav.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor yellowColor]};
    return nav;
}


/**
 *  返回取消渲染的image
 */
- (UIImage *)removeRendering:(NSString *)imageName
{
    UIImage * image = [UIImage imageNamed:imageName];
    return [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}



@end
